﻿using System;
using System.Collections.Generic;
using System.Text;
using CadStrategy2013.DxfData;
using MyIni;

namespace CadStrategy2013.CgqStyle
{
    public class ZLDcClass:Cgq2013
    {
        public ZLDcClass(string secname)
            : base(secname)
        {
        }
        public ZLDcClass(string secname, Dictionary<string, string> dic)
            :base(secname,dic)
        {
        }
        //public override void GetCfg()
        //{
        //    base.GetCfg();
        //    GetCfg("直流道岔电流");
        //}
        public override List<string> ReadTemplateDxf()
        {
            return ReadDxf(Path + "\\template\\直流道岔电流.dll");
        }
        public override string GetSaveFileName(int index)
        {
            if (ShiJiTuZhiCount == 1)
                return "\\直流道岔电流.dxf";
            return "\\直流道岔电流" + (index + 1).ToString() + ".dxf";
            //if (index == 0)
            //    return "\\直流道岔电流.dxf";
            //else
            //    return "\\直流道岔电流" + index + ".dxf";
        }
        public override DxfDataClass GetDxfData()
        {
            DxfDataClass dxfDataClass = new DxfDataClass();

            IniFile inifile = new IniFile("./\\" + StationName + "\\dc.txt");
            int sum0 = inifile.GetInt16("直流道岔", "sum", 0);
            string[] strDLDingXing = inifile.GetString("直流道岔", "电流定型", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string str1Dqj = inifile.GetString("直流道岔", "1DQJ", "");
            string strDB = inifile.GetString("直流道岔", "DB", "");
            string strFB = inifile.GetString("直流道岔", "FB", "");
            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("直流道岔", (i + 1).ToString(), "");
                string[] s = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int n = s.Length;
                devClass.DevName = s[0];
                if (n <= 2)
                {
                    devClass.peiList.Add(str1Dqj);
                    devClass.peiList.Add(strDB);
                    devClass.peiList.Add(strFB);
                    devClass.cpeiList.Add(strDLDingXing[0]);
                    devClass.cpeiList.Add(strDLDingXing[1]);
                }
                else
                {
                    devClass.peiList.Add(s[2] + "-" + str1Dqj);
                    devClass.peiList.Add(s[2] + "-" + strDB);
                    devClass.peiList.Add(s[2] + "-" + strFB);
                    devClass.cpeiList.Add(s[2] + "-" + strDLDingXing[0]);
                    devClass.cpeiList.Add(s[2] + "-" + strDLDingXing[1]);
                }
                //devClass.cpeiList.Add(s[2] + "-" + strDLDingXing[1]);
                dxfDataClass.devList.Add(devClass);
            }
            if (sum0 != 0)
            {
                ShiJiBanCount = (dxfDataClass.devList.Count - 1) / BanDevCount + 1;
                ShiJiTuZhiCount = (ShiJiBanCount - 1) / BanCount + 1;
            }
            else
            {
                ShiJiBanCount = 0;
                ShiJiTuZhiCount = 0;
            }
            m_dxfDataClass = dxfDataClass;
            return dxfDataClass;
        }
        //public override string ReplacePei(string str, int fi = 0)
        //{
        //    for (int j = 1; j <= BanCount; j++)
        //    {
        //        int nj = j;// -fi * BanCount;
        //        for (int i = 1; i <= 2 * BanDevPeiCount * BanDevCount; i++)
        //        {
        //            string str1 = "pei" + nj.ToString() + "-" + i.ToString() + ">";
        //            if (str.Contains(str1))
        //            {
        //                int index = (fi * BanCount + j - 1) * BanDevCount + (i - 1) / BanDevPeiCount;
        //                if (index >= m_dxfDataClass.devList.Count)
        //                    return "";
        //                int index1 = (i - 1) % 3;
        //                try
        //                {
        //                    str = str.Replace(str1, m_dxfDataClass.devList[index].peiList[index1]);
        //                }
        //                catch (Exception e)
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return str;
        //}
        //public override  string ReplaceCPei(string str, int fi = 0)
        //{
        //    for (int j = 1; j <= BanCount; j++)
        //    {
        //        int nj = j;// -fi * BanCount;
        //        for (int i = 1; i <= BanDevCount; i++)
        //        {
        //            string str1 = "cpei" + nj.ToString() + "-" + i.ToString() + ">";
        //            if (str.Contains(str1))
        //            {
        //                int index = (fi * BanCount + j - 1) * BanDevCount + (i - 1);
        //                if (index >= m_dxfDataClass.devList.Count)
        //                    return "";
        //                //int index1 = (i - 1);
        //               // if (m_dxfDataClass.devList[index].cpeiList.Count > 1)
        //                try
        //                {
        //                    str = str.Replace(str1, m_dxfDataClass.devList[index].cpeiList[0]);
        //                }
        //                catch (Exception e)
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return str;
        //} 
    }
}
